
const tokens = {
  admin: {
    token: 'admin-token'
  },
  editor: {
    token: 'editor-token'
  },
  zhujun: {
    token: 'zhujun-token'
  },
  brand: {
    token: 'brand-token'
  },
  member: {
    token: 'member-token'
  }
}

const users = {
  'admin-token': {
    roles: ['ADMIN'],
    introduction: 'I am a super administrator',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Super Admin'
  },
  'editor-token': {
    roles: ['editor'],
    introduction: 'I am an editor',
    avatar: 'http://b-ssl.duitang.com/uploads/item/201809/11/20180911211800_ifnnv.thumb.700_0.jpg',
    name: 'Normal Editor'
  },
  'zhujun-token': {
    roles: ['zhujun'],
    introduction: 'I am an ZhuJun',
    avatar: 'http://img4.imgtn.bdimg.com/it/u=3430337040,2591943044&fm=26&gp=0.jpg',
    name: 'ZhuJun'
  },
  'brand-token': {
    roles: ['brand'],
    introduction: 'I am an brand',
    avatar: 'http://images.liqucn.com/img/h1/h968/img201709200923590_info300X300.jpg',
    name: 'brand'
  },
  'member-token': {
    roles: ['member'],
    introduction: 'I am an member',
    avatar: 'http://img.duoziwang.com/2017/04/29/B0432.jpg',
    name: 'member'
  }
}

export default [
  // user login
  {
    url: '/user/login',
    type: 'post',
    response: config => {
      const { username } = config.body
      const token = tokens[username]
      console.log(token)
      // mock error
      if (!token) {
        return {
          code: 60204,
          message: '账号密码错误'
        }
      }

      return {
        code: 20000,
        data: token
      }
    }
  },

  // get user info
  {
    url: '/user/info\.*',
    type: 'get',
    response: config => {
      const { token } = config.query
      const info = users[token]

      // mock error
      if (!info) {
        return {
          code: 50008,
          message: '登录失败，无法获取用户详细信息.'
        }
      }

      return {
        code: 20000,
        data: info
      }
    }
  },

  // user logout
  {
    url: '/user/logout',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  }
]
